Skip to main content

Execute VBAScript

AutomatR.Excel.Activities.ExecuteVBAScript

The "Execute VBA Script" activity in AutomatR is part of the Excel activities package, designed to invoke a macro from an external file containing VBA code and execute it against an Excel file. This activity is useful for running custom VBA scripts within Excel as part of an automated workflow.

NOTE: To work with Execute VBAScript activity, enable the Trust Access to the VBA project object model from Excel by navigating to (File >> Options >> Trust Center >> Trust Center Settings >> Macro Settings >> Select the Trust Access to the VBA project object model check box). Enable VBA project object model!

Properties

NameDescription
Input
Code File PathEnter the VBA script file path located locally with code to be executed on an Excel file. String variables containing the file path.
Enter Method NameEnter the method name in the code file. String variables containing the method name. If not provided, the default method "Main" is used.
Enter Method ParamsEnter the parameters/arguments in the code file as an Enumerable object list.
Misc
Display NameThe display name of the activity. A display name is automatically generated when you indicate a target.
Optional
DelaySpecifies the amount of time (in seconds) to wait before executing the "Execute VBA Script" activity. This can be useful for handling synchronization issues. Integer variables containing the delay duration. Example: If the amount of time is 1000 milliseconds or 1 sec, i.e., 1.
Output
OutputReturns the results as an object based on the method output in the code file. Variables of relevant types to store the method output.

How to use:

  1. Drag and drop the "Execute VBA Script" activity onto the workflow.
  2. Configure the properties by specifying the VBA script file path and, optionally, providing the method name and parameters.
  3. Optionally, configure the delay.
  4. Execute the workflow to run the specified VBA script within the Excel workbook.

Example: Consider an example where the "Execute VBA Script" activity is used to execute a VBA script named "MyScript" with parameters:

Execute VBA Script:
Code File Path: "C:\Scripts\MyScript.vba"
Enter Method Name: "RunScript"
Enter Method Params: {param1, param2, param3}
Delay: 2

In this example, the activity executes the "RunScript" method within the "MyScript.vba" file located at "C:\Scripts\". The parameters "param1," "param2," and "param3" are provided to the script. The execution is delayed by 2 seconds as specified in the delay property.

Note: Ensure that the "Execute VBA Script" activity is placed within an "Excel Root" activity to establish the Excel context for execution.